﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Utilities;
using System.IO;

namespace t_Utilities
{
    /// <summary>
    /// Summary description for t_Image
    /// </summary>
    [TestClass]
    public class t_Image
    {
        public t_Image()
        {
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void GetSizes()
        {
            FileInfo f = new FileInfo("..\\..\\..\\t_DTBuilderLib\\file1.jpg");
            int[] sizes = Image.GetImageSize(f);

            Assert.IsTrue(sizes.Length == 2, "Wrong number of pixel dimensions came back!");
            Assert.IsTrue(sizes[0] == 6000, "X Size of image is incorrect");
            Assert.IsTrue(sizes[1] == 4500, "Y Size of image is incorrect");

        }

        [TestMethod]
        public void RotateImage()
        {
            FileInfo f = new FileInfo("..\\..\\..\\t_DTBuilderLib\\file1.jpg");
            int[] sizes = Image.GetImageSize(f);

            string name = f.Name.Substring(0, f.Name.Length - f.Extension.Length);
            FileInfo picCopy = new FileInfo(name + "-rotated.jpg");
            f.CopyTo(picCopy.FullName, true);

            Image.RotateInPlace(picCopy);

            int[] rsizes = Image.GetImageSize(picCopy);
            Assert.IsTrue(rsizes[0] == sizes[1], "Rotation seems to have failed on r X");
            Assert.IsTrue(rsizes[1] == sizes[0], "Rotation seems to have failed on r Y");
        }

        [TestMethod]
        public void TestOrientation()
        {
            FileInfo f = new FileInfo("..\\..\\..\\t_DTBuilderLib\\file1.jpg");
            Assert.IsTrue(Image.IsLandscape(f), "Image is in landscape, but that is false!");

            string name = f.Name.Substring(0, f.Name.Length - f.Extension.Length);
            FileInfo picCopy = new FileInfo(name + "-orientedrotated.jpg");
            f.CopyTo(picCopy.FullName);
            Image.RotateInPlace(picCopy);

            Assert.IsFalse(Image.IsLandscape(picCopy), "Portrait is listed as being in landscape!");
        }

    }
}
